package org.jeecg.demo.wx.runner;

import org.jeecg.common.util.RedisUtil;
import org.jeecg.demo.wx.constant.CacheConstant;
import org.jeecg.demo.wx.convert.EScheduledTypeConvert;
import org.jeecg.demo.wx.entity.EScheduledType;
import org.jeecg.demo.wx.service.IEScheduledTypeService;
import org.jeecg.demo.wx.vo.EScheduledTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 功能描述
 * 日程类型缓存预热
 *
 * @author: zgq
 * @date: 2024年01月30日 20:27
 */
@Component
public class ScheduleTypeRunner implements CommandLineRunner {

    @Autowired
    private IEScheduledTypeService eScheduledTypeService;
    @Autowired
    private RedisUtil redisUtil;


    @Override
    public void run(String... args) throws Exception {
        List<EScheduledType> eScheduledTypes = eScheduledTypeService
                .lambdaQuery()
                .select(EScheduledType::getName, EScheduledType::getId)
                .eq(EScheduledType::getDelFlag, 0)
                .list();
        List<EScheduledTypeVo> eScheduledTypeVos = EScheduledTypeConvert.INSTANCE.convertList(eScheduledTypes);
        redisUtil.set(CacheConstant.WX_SCHEDULED_TYPE_KEY, eScheduledTypeVos);
    }
}
